﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using YAPL.Language.Core;
using YAPL.Language.Core.Exceptions;
using YAPL.Language.Core.Types;

namespace YAPL.Test.YAPL.Language.Core.Lib.GlobalFunctions {
	public class ParseFloatTest {
		private readonly YAPLFunction _parseFloat;

		public ParseFloatTest() {
			_parseFloat = GCL.Get(ClassNames.GlobalScope).Methods[FunctionNames.ParseFloat];
		}

		[Fact]
		public void ValidFloatShouldBeParsedCorrectly() {
			YAPLFloat result = null;
			var scope = new Scope();
			scope["unnamed0"] = new YAPLString("12.3");
			Assert.DoesNotThrow(() => result = (YAPLFloat)_parseFloat.Call(scope));
			Assert.NotNull(result);
			Assert.Equal(12.3,result.FloatValue);
		}

		[Fact]
		public void InvalidFloatShouldThrowException() {
			var scope = new Scope();
			scope["unnamed0"] = new YAPLString("sdfsf");
			Assert.Throws<YAPLBadArgumentException>(() => _parseFloat.Call(scope));
		}
	}
}
